﻿// See https://aka.ms/new-console-template for more information
using Demo;
using System.Net;

int destPort = 9876;
IPAddress serverIp = IPAddress.Loopback;
if (args.Length> 0 && args[0].ToLower() == "s")
{
    TcpServerDemo serverDeno = new TcpServerDemo();
    if(serverDeno.Start(serverIp, destPort))
    {
        Console.WriteLine($"启动服务端成功Port:{destPort}");
        while (true)
        {
            await Task.Delay(100);
        }
    }
    else
    {
        Console.WriteLine("启动服务端失败。");
    }
}
else
{

    TcpClientDemo tcpClientDemo = new TcpClientDemo();
    if (tcpClientDemo.Start(serverIp, destPort))
    {
        Console.WriteLine($"启动客户端成功。");
        while (true)
        {
           var pushMsg = Console.ReadLine();
            tcpClientDemo.PushMsg(pushMsg ?? "空消息");
        }
    }
    else
    {
        Console.WriteLine("启动客户端失败。");
    }
}

